//888888888888888888888888888888888888888888888888888888888888888888888888888888888888888
//
//	File		 :	RTFFormattedOutput.h
//	Contents	 :	Source file for class CFormattedOutput
//	Creation Date:	22/12/1999
//	Last Modified:	23/12/1999	lg
//	tabs width	 :	every 4 characters

//
//888888888888888888888888888888888888888888888888888888888888888888888888888888888888888

#if !defined(RTFFORMATTEDOUTPUT_H)
#define RTFFORMATTEDOUTPUT_H


#include "formattedoutput.h"


//_______________________________________________________________________________________
//
//	CRTFFormattedOutput
//
//		Produces formatted text in the Microsoft Rich Text Format
//
//		Generally, the only necessary function calls are (in order):
//
//			1) AddFormat/AddFormats:
//				adds all the text formats which will be used throughout
//
//			2) BeginHeader()
//
//			3) AddText, AddNewLine
//			   SetFormat
//				switches to one of the formats from AddFormat(s)
//
//			5) EndFooter()
//
//			6) 	CopytoClipboard() or
//				GetStreamedText() or
//				CopyToWord()	  or
//				AddToWordDocument()
//_______________________________________________________________________________________
class CRTFFormattedOutput : virtual public CFormattedOutput
{
	// data
	std::string				FormattedStream;
							// map colours to RTF colour table
	std::vector<unsigned>	TextColourIndices;
	std::vector<unsigned>	BackColourIndices;
	std::vector<CColourref>	ColourTable;

	//inline functions
	void					StreamText(char* s);
	void					StreamText(char s);
	void					StreamText(const std::string& s);
	void					ClearStream();
protected:
	void					StreamQueuedText();
	virtual void			DoBeginHeader();
	virtual void			DoEndFooter();
#ifdef _MFC_VER	// mfc specific code to follow
	unsigned					GetClipboardFormat(unsigned i);
#endif
public:
							CRTFFormattedOutput(unsigned ts = 100,
								const std::string& tf = "Courier New"):
								CFormattedOutput(ts, tf){}
	const std::string&		GetStreamedText(unsigned i);
	void					AddNewLine();
	void					AddDoubleNewLines();
	void					AddNewLineAndHalf();
	unsigned				GetFileFormatCounts();
#ifdef _MFC_VER	// mfc specific code to follow
	const std::string&		GetClipStreamedText(unsigned i);
#endif
};

//888888888888888888888888888888888888888888888888888888888888888888888888888888888888888
//
//	CRTFFormattedOutput
//
//		inlines mainly for encapsulation
//
//888888888888888888888888888888888888888888888888888888888888888888888888888888888888888
inline void CRTFFormattedOutput::StreamText(char* s)
{
	FormattedStream += s;
}

inline void CRTFFormattedOutput::StreamText(char s)
{
	FormattedStream += s;
}

inline void CRTFFormattedOutput::StreamText(const std::string& s)
{
	if (FormattedStream.length() + s.length() > FormattedStream.capacity())
		FormattedStream.reserve(FormattedStream.length() * 2 + 1);
	FormattedStream.append(s);
}

//_______________________________________________________________________________________
//
//	ClearStream
//
//		Reinitialize Stream, should be called by BeginHeader()
//		Last modified: lg 23/12/1999
//
//_______________________________________________________________________________________
inline void CRTFFormattedOutput::ClearStream()
{
	FormattedStream.erase();
}


#endif // !defined(RTFFORMATTEDOUTPUT_H)
